#ifndef _TAROT_CARDSET_H
#define _TAROT_CARDSET_H

#include <stdio.h>
#include "../Main.h"
#include "../occult/Occult.h"
#include "Card.h"


enum {
	CARDSET_VISIBLE			= 0x0001,
};

class aRandom;


class CardSet {
protected:
	char *name;						/**< Name of CardSet. */
	int sz;							/**< Number of cards in the full deck. */
	int cap;							/**< Capacity in the array "cards". */
	Card **cards;					/**< The full deck of cards. */
	int width;						/**< Width of the back card. */
	int height;						/**< Height of the back card. */
	int state;

	virtual FILE *openFile(const char *fn) { return 0; }
	virtual void readHeader(FILE *fp);
	virtual void readCards(FILE *fp) {}

public:
friend class Card;

	CardSet();
	virtual ~CardSet();

	CardSet &operator=(const CardSet &c);

	char *getName() { return name; }
	int size() { return sz; }
	int getWidth() { return width; }
	int getHeight() { return height; }

	bool isVisible() { return state&CARDSET_VISIBLE; }
	void setVisible(bool v) { state = v? state|CARDSET_VISIBLE : state&~CARDSET_VISIBLE; }

	Card *getCard(int n) { return n<sz? cards[n] : 0; }
	Card *getCardByValue(int v);
	CardSet getCards(const int *s,int n);
	CardSet getCardsByValue(const int *s,int n);

	virtual void paint(cairo_t *cr,GdkRectangle *rects=0,int nrects=0);

	void load(const char *nm);
	void loadHeader(const char *nm);

	void sort();
	void mix(aRandom &r,int st=0,int rev=0);
	void reverseOrder();
	int moveToBottom(Card &c);
	int moveToTop(Card &c);
	void add(Card &c);
	void remove(Card &c);

	void spreadArch(GdkRectangle &r);
	void spreadSorted(GdkRectangle &r,int p,int fr,int to);

	void setCardState(int s,bool set);
	void showFront() { setCardState(CARD_BACK,false); }
	void showBack() { setCardState(CARD_BACK,true); }
};



#endif /* _TAROT_CARDSET_H */


